<?php

function ListImagesByType($type,$idP=0)
{
    global $dbsql,$language,$folder_img_upload;    
    $idP        = intval($idP);
	$sql_select = "SELECT * FROM tblimages where cType='$type' and iParentId=$idP  order by iOrder";

	$rs         = $dbsql->query($sql_select);
    $html_str   = '';
	while($result = $dbsql->fetch_array($rs) )
	{
		$file             = basename($result['cImage']);
		$result['cThumb'] = str_replace($file,"thumbs/".$file,$result["cImage"]);
        $html_str       .= "addrow({id: ".$result['iId'].",n: '".$result['cName']."',r:'../".$folder_img_upload."',p:'',f:'".$result['cImage']."'});";
         
	}
    return $html_str;
}

function InsertImages($name,$url,$order,$type,$idP)
{
    global $dbsql,$language;
    if(empty($name) || empty($url))
    {
        return false;
    }
    $idP        = intval($idP);
    $order      = intval($order);
    $sql_insert = "INSERT INTO tblimages
					(cName,iParentId,cImage,iOrder,cType,cLanguage)
				VALUE('$name','$idP','$url',$order,'$type','$language')";

	return $dbsql->query($sql_insert);
}

function UpdateImages($name,$order,$id)
{
    global $dbsql;
    $order      = intval($order);
    
    $sql_update = "UPDATE tblimages SET
        			 cName = '$name',
                     iOrder= '$order'
        			 WHERE iId = '$id'";
    $dbsql->query($sql_update);
}

function DeleteImages($id)
{
    global $dbsql;
    $id             = intval($id);
    $sql_delete     = "delete from tblimages where iId=$id";
    return $dbsql->query($sql_delete);
    
}